
//引入css
require("../css/mine.less")
require("../fonts/iconfont.css")

//无账号的登录拦截
window.$utils.checkLogin()

//注册change事件
// window.location.reload(1)
document.ready(function () {
    window.$utils.creatFooter(2)
    let uid = JSON.parse(window.localStorage.getItem("user"))
    console.log(uid);
    let upimg = document.querySelector("#upimg")
    let ibox = document.querySelector(".ibox")
    let h3 = document.querySelector(".sportData-top")
    let s = ""
    upimg.addEventListener("change", function () {
        console.log(this.files[0]);
        window.$updateFile("/users/upload", "imgurl", this.files[0], function (res) {
            console.log(res);
            if (res.status == 0) {
                //接收图片在服务器上的地址,左边为服务器地址,右边为图片在服务器内的相对路径
                s = 'http://139.9.177.51:8099' + res.data
                ibox.src = s
                window.$http.post("/users/userEdit", {
                    userId: uid.userId,
                    imgurl: s
                }, function (res) {
                    if (res.status == 0) {
                        window.$utils.tick(0, "上传成功")
                    }
                })
            }
        })
    })


    //点击头像注册事件
    ibox.addEventListener("click", function () {
        upimg.click() //通过点击事件触发change事件
    })

    //页面加载获取数据
    window.$http.get("/users/accountinfo?userId=" + uid.userId, function (res) {
        console.log(res);
        h3.innerHTML = res.data.nickname
        ibox.src = res.data.imgurl
    })

    let back = document.querySelector(".back>a")
    back.addEventListener("click", function () {
        window.localStorage.clear() //退出登录清空本地存储数据
        location.reload()//刷新页面
    })

})